// pages/estate/list/index.js
var app = getApp(), fetchApi = require("../../../utils/httpPost.js"),
formatTime = require("../../../component/common.js")
import Toast from '../../../component/vant/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeTab: 0,
    customIndexList: [1, 2, 3, 4, 5, 6, 8, 9, 10],
    scrollTop: 0,
    cityList:[],
    city_names:[],
    keyword:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.onHttpInit()
  },

  onSearch(val){
    console.log('onSearch',val)
    this.data.keyword = val.detail;
    this.onHttpInit()
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost('/user/city/listByCharacters', {
      keyword: that.data.keyword
    }, function (res) {
      console.log("城市列表数据", res)
      if(res.data.code == 0){
        that.setData({
          cityList : res.data.data.cityList,
        })
      }
      that.setData({
        netWork: true,
      })
    }, function () {
        that.setData({ netWork: false, hasData: false })
    })
  },
  chooseCity(e){
    var cityId = e.currentTarget.dataset.cityid;
    var cityName = e.currentTarget.dataset.cityname;
    
    wx.navigateTo({
      url: 'url',
    })
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面
    prevPage.setData({
      city_id: cityId,
      city_name: cityName,
      action:'change_city'
    })
    console.log('pages prevPage 2 ',prevPage)
    wx.navigateBack({ delta: -1 });
  }
})